import React, { useState,useEffect,useContext } from 'react';
import { Button, Modal, Form, Input, Switch, Space, message } from 'antd';
const { TextArea } = Input;
import { setRefundRes} from '../../../../api/OrderApi'
import myContext from '../../../../utils/myContext'
 
interface DataType {
    key: React.Key;
    id: number;
    reason_desc: string;
    sort: number;
    isOpen: boolean;
    addTime: string
}

interface PropsType {
    isEditModalOpen: boolean;
    close(): void;
    orderId:number;
    initRemark:string
    // record:DataType
}




function EditRemark(props: PropsType) {

    const [remark,setRemark]=useState<string>('hahah')
    const context=useContext<any>(myContext)
    console.log('props.remark',props.initRemark);
    

    const handleOk = () => {
        props.close()
        console.log('remark',remark);
        // 发请求修改备注信息
        setRefundRes({
            orderId:props.orderId,
            handlingRemark:remark
        }).then(res=>{
            console.log('同意退款',res);
            message.success('修改备注成功')
            // console.log('context',context);
            
            context.getDetail()
        }).catch(err=>{
            console.log('err34343434',err);         
        })
      };
    
      const handleCancel = () => {
        props.close()
      };
    //   文本框值变化的回调函数
      const changeHandle=(e:any)=>{
        setRemark(e.target.value)
    }


    // 页面首次加载获取初始值
    useEffect(()=>{
        setRemark(props.initRemark)
    },[props.initRemark])

    return (
        <>
            <Modal title="修改备注信息" open={props.isEditModalOpen} forceRender onOk={handleOk} onCancel={handleCancel}>
                <TextArea rows={4} value={remark}  showCount onChange={()=>changeHandle(event)}/>
                
            </Modal>
        </>
    );
};

export default EditRemark;